package com.yd.app.mapper.provider;

import com.alibaba.druid.util.StringUtils;
import com.yd.domain.business.Agreement;

import java.util.Map;

/**
 * 协议
 * Created by zg on 2018/3/7.
 */
public class AgreementProvider extends BaseProvider {
    /**
     * 获取每一页列表
     * @param map
     * @return
     */
    public String searchAgreementList(Map map) {
        Agreement agreement = (Agreement) map.get("agreement");
        StringBuilder sb = new StringBuilder("SELECT * FROM business_agreement where 1=1 ");
        sb.append(searchOtherSql(agreement));
        sb.append(" limit #{startRow},#{pageSize} ");
        return sb.toString();
    }

    /**
     * 获取查询总数量
     * @param map
     * @return
     */
    public String getAgreementListCount(Map map) {
        Agreement agreement = (Agreement) map.get("agreement");
        StringBuilder sb = new StringBuilder(" select count(1) from business_agreement where 1=1");
        sb.append(searchOtherSql(agreement));
        return sb.toString();
    }

    /**
     * 拼装查询条件
     * @param agreement
     * @return
     */
    public String searchOtherSql(Agreement agreement) {
        StringBuilder sb = new StringBuilder();
        if(!StringUtils.isEmpty(agreement.getTitle())&&!"".equals(agreement.getTitle())){
            sb.append(" and title like" +" '%"+agreement.getTitle().trim()+"%'  ");
        }
        return sb.toString();
    }
}
